// npm install vue-router -S    
import VueRouter from 'vue-router';
import Vue from 'vue';

import Index from './page/index.vue';
import Shop from './page/shop.vue';
import Mine from './page/mine.vue';
import Buycar from './page/buycar.vue';
import News from './page/news.vue';
import Login from './page/login.vue';
import Register from './page/register.vue';
import Detail from './page/detail.vue';


// 将vue-router注册到全局，这样每一个组件都可以使用router-link和router-view组件了
Vue.use(VueRouter);

// 定义路由规则
var routes = [
    { path: '/', component: Index },
    { path: '/news/:id', component: News },
    { path: '/shop', component: Shop },
    {
        path: '/mine', component: Mine, children: [
            { path: '/mine/login', component: Login },
            { path: '/mine/register', component: Register }
        ]
    },
    { path: '/buycar', component: Buycar, params: { a: 1, b: 2 } },
    {
        name: 'xq', path: '/detail', component: Detail, beforeEnter: (to, from, next) => {
            //console.log(to, from);
            next();
        }
    }
]

// 创建路由实例
var router = new VueRouter({ routes, mode: 'history' });

export default router;